import moment from "moment";
import util from "../../utils/apl-common";
Component({
  options: {
    addGlobalClass: true
  },
  /**
   * 组件接受的外部式样类
   */
   externalClasses: ["cutom-class"],
  /**
   * 组件的属性列表
   */
  properties: {
    /**订单数据 */
    orderData: {
      type: Object,
    },
    /**右上角是否显示标签 */
    labelShow: {
      type: Boolean,
      value: false,
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    /**订单渲染数据 */
    orderDataNew: {},
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onDetail(e) {
      let orderDataset = e.currentTarget.dataset.order;
      var myEventDetail = {
        orderDataset,
      };
      var myEventOption = {};
      this.triggerEvent("orderDetail", myEventDetail, myEventOption);
    },
    onStop(e) {
      let orderDataset = e.currentTarget.dataset.order;
      var myEventDetail = {
        orderDataset,
      };
      var myEventOption = {};
      this.triggerEvent("orderStop", myEventDetail, myEventOption);
    },
    onStart(e) {
      let orderDataset = e.currentTarget.dataset.order;
      var myEventDetail = {
        orderDataset,
      };
      var myEventOption = {};
      this.triggerEvent("orderStart", myEventDetail, myEventOption);
    },
    onEnd(e) {
      let orderDataset = e.currentTarget.dataset.order;
      var myEventDetail = {
        orderDataset,
      };
      var myEventOption = {};
      this.triggerEvent("orderEnd", myEventDetail, myEventOption);
    },
    onLog(e) {
      let orderDataset = e.currentTarget.dataset.order;
      var myEventDetail = {
        orderDataset,
      };
      var myEventOption = {};
      this.triggerEvent("orderLog", myEventDetail, myEventOption);
    },
    /**
     * 设置订单数据
     * @param {*} item 订单数据源
     */
    setOrderData(item) {
      let orderDataNew = {};
      orderDataNew.orderId = item.orderId;
      orderDataNew.serviceId = item.serviceId;
      orderDataNew.dispatchId = item.dispatchId;
      orderDataNew.workStatus = item.workStatus;
      if (item.serviceCategory == "YS") {
        orderDataNew.title = `${item.serviceCategory_dictText} | ${item.serviceRank_dictText} ${item.serviceDays}${item.serviceUnit_dictText}`;
      } else {
        if(item.serviceUnit == '2') {
          orderDataNew.title = `${item.serviceCategory_dictText} ${item.serviceDays}${item.serviceUnit_dictText}`;
        }else {
          orderDataNew.title = `${item.serviceCategory_dictText} ${item.serviceCount}${item.serviceUnit_dictText}`;
        }
      }
      orderDataNew.customerName = item.customerName;
      orderDataNew.contectTel = item.contectTel;
      orderDataNew.addressDetail = item.addressDetail;
      orderDataNew.planStartTime = moment(
        util.insertStr(item.planStartTime, 8, " ")
      ).format("YYYY-MM-DD hh:mm:ss");
      orderDataNew.planEndTime = moment(
        util.insertStr(item.planEndTime, 8, " ")
      ).format("YYYY-MM-DD hh:mm:ss");
      orderDataNew.actStartTime = moment(
        util.insertStr(item.actStartTime, 8, " ")
      ).format("YYYY-MM-DD hh:mm:ss");
      orderDataNew.actEndTime = moment(
        util.insertStr(item.actEndTime, 8, " ")
      ).format("YYYY-MM-DD hh:mm:ss");
      this.setData({
        orderDataNew,
      });
    },
  },

  /**
   * 组件生命周期
   */
  lifetimes: {
    attached() {
      this.setOrderData(this.data.orderData);
    },
  },
});
